<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请开票列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目编号：</label>
                                <input type="text" autoComplete="off" name="orderNo"/>
                            </li>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" autoComplete="off" name="xmmc"/>
                            </li>
                            <li>
                                <label>申请时间：</label>
                                <input type="text" autoComplete="off" class="time-input" placeholder="请选择申请时间" name="sqsj"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">&nbsp;
<!--             	<a class="btn btn-info multiple disabled" id="button-yes" > -->
<!--                     <i class="fa fa-check"></i> 审核通过 -->
<!--                 </a> -->
<!--                 <a class="btn btn-danger multiple disabled" id="button-no" > -->
<!--                     <i class="fa fa-remove"></i> 审核拒绝 -->
<!--                 </a> -->
                <a class="btn btn-success single disabled" onclick="sqkpprint()" shiro:hasPermission="gcgl:sqkp:print">
                    <i class="fa fa-download"></i> 打印开票申请单
                </a>
                <a class="btn btn-info single disabled" id="button-quer" shiro:hasPermission="gcgl:qrsk:add">
                    <i class="fa fa-check"></i> 确认收款
                </a>
                <a class="btn btn-info single disabled" id="button-lis" shiro:hasPermission="gcgl:qrsk:view">
                    <i class="fa fa-check"></i> 查看收款台账
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var types = [[${@dict.getType('gcgl_project_type')}]];
        var fps = [[${@dict.getType('gcgl_project_fp')}]];
    	var statuss = [[${@dict.getType('gcgl_sqfp_status')}]];
        var prefix = ctx + "gcgl/sqkp";

        $(function() {
            var options = {
                url: prefix + "/hjpslist",
                detailUrl: prefix + "/sqkphjsp/{id}",
                modalName: "申请开票",
                sortName: "orderno desc",
                sortOrder: "",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'gcProjectid',
                    title: '合同ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '项目编号'
                },
                {
                    field: 'xmmc',
                    title: '项目名称'
                },
                {
                    field: 'htje',
                    title: '合同金额'
                },
                {
                    field: 'itemje',
                    title: '申请开票金额'
                },
                {
                    field: 'sqsj',
                    title: '申请时间',
                    width: '90'
                },
                {
                    field: 'xmfzr',
                    title: '项目负责人'
                },
                {
                    field: 'sqrpr',
                    title: '工程复核',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==0){
                        	actions.push('-');
                        }else{
                        	actions.push(value);
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'zjlsp',
                    title: '总经理'
                },
                {
                    field: 'cwkpr',
                    title: '财务审核'
                },
                {
		            field: 'status',
		            title: '状态',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(statuss, item.status);
		            }
		        },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        $("#button-yes").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        	
	    	$.modal.confirm("确认要审核通过吗?", function() {
	    		$.ajax({
    				url: "/gcgl/sqkp/hjyes",
    				type: "post",
    				data: { "ids": rows.join() },
    				dataType: 'json',
    				success: function(data) {
    					$.table.refresh();
    				},
    				error: function(xhr, type, errorThrown) {
    					//异常处理；
    					$.modal.alert("请稍后再试！");
    					$.table.refresh();
    				}
    			});
	    	});
	    })
	    
	    $("#button-no").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        	
	    	$.modal.confirm("确认要审核拒绝吗?", function() {
	    		$.ajax({
    				url: "/gcgl/sqkp/hjno",
    				type: "post",
    				data: { "ids": rows.join() },
    				dataType: 'json',
    				success: function(data) {
    					$.table.refresh();
    				},
    				error: function(xhr, type, errorThrown) {
    					//异常处理；
    					$.modal.alert("请稍后再试！");
    					$.table.refresh();
    				}
    			});
	    	});
	    })
	    
	    //打印增值税发票开具申请单
	    function sqkpprint(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.openTab('打印增值税发票开具申请单',"/gcgl/sqkp/sqkpprint/"+rows.join());
        }
        
      	//确认收款
        $("#button-quer").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            
            if(status==5){
            	$.modal.open('确认付款',"/gcgl/qrsk/add/"+rows.join());
            	/**
            	$.modal.confirm("确认该款项收款吗?", function() {
    	    		$.ajax({
        				url: "/gcgl/sqkp/hjconfirm",
        				type: "post",
        				data: { "ids": rows.join() },
        				dataType: 'json',
        				success: function(data) {
        					$.table.refresh();
        				},
        				error: function(xhr, type, errorThrown) {
        					//异常处理；
        					$.modal.alert("请稍后再试！");
        					$.table.refresh();
        				}
        			});
    	    	});
            	**/
            }else if(status==7){
            	$.modal.alertWarning("该记录已付款完成！");
                return;
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
	    })
	    
	  	//查看收款台账
        $("#button-lis").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.open('确认付款',"/gcgl/qrsk/"+rows.join());
	    })
    </script>
</body>
</html>